package com.selfdriving.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.selfdriving.BaseApplication;
import com.selfdriving.BaseObjectListAdapter;
import com.selfdriving.R;
import com.selfdriving.bean.Entity;
import com.selfdriving.bean.Ranking;
import com.selfdriving.utils.PhotoUtil;
import com.selfdriving.utils.StringUtil;

public class RankingAdapter extends BaseObjectListAdapter
{

	public RankingAdapter(BaseApplication application, Context context,
			List<? extends Entity> datas)
	{
		super(application, context, datas);
		// TODO Auto-generated constructor stub
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		ViewHolder holder = null;
		if (convertView == null)
		{
			convertView = mInflater.inflate(R.layout.popular_list_item, null);
			holder = new ViewHolder();
			holder.name = (TextView) convertView.findViewById(R.id.tvName);
			holder.num = (TextView) convertView.findViewById(R.id.tvNum);
			holder.icon = (ImageView) convertView.findViewById(R.id.ivPosition);
			holder.icon1 = (ImageView) convertView
					.findViewById(R.id.ivPosition1);
			holder.icon2 = (ImageView) convertView
					.findViewById(R.id.ivPosition2);
			holder.icon3 = (ImageView) convertView
					.findViewById(R.id.ivPosition3);
			holder.postion = (TextView) convertView
					.findViewById(R.id.tvPosition);
			convertView.setTag(holder);
		} else
		{
			holder = (ViewHolder) convertView.getTag();
		}
		Ranking ranking = (Ranking) mDatas.get(position);
		if (!StringUtil.isNullOrEmpty(ranking.getName()))
		{
			holder.name.setText(ranking.getName());
		}

		if (!StringUtil.isNullOrEmpty(ranking.getClick()))
		{
			holder.num.setText(ranking.getClick());
		}

		if (position == 0)
		{
			holder.icon.setVisibility(View.VISIBLE);
			holder.icon1.setVisibility(View.GONE);
			holder.icon2.setVisibility(View.GONE);
			holder.icon3.setVisibility(View.GONE);
			holder.postion.setVisibility(View.GONE);
		} else if (position == 1)
		{
			holder.icon.setVisibility(View.GONE);
			holder.icon1.setVisibility(View.VISIBLE);
			holder.icon2.setVisibility(View.GONE);
			holder.icon3.setVisibility(View.GONE);
			holder.postion.setVisibility(View.GONE);
		} else if (position == 2)
		{
			holder.icon2.setVisibility(View.VISIBLE);
			holder.icon1.setVisibility(View.GONE);
			holder.icon.setVisibility(View.GONE);
			holder.icon3.setVisibility(View.GONE);
			holder.postion.setVisibility(View.GONE);
		} else if (position == 3)
		{
			holder.icon3.setVisibility(View.VISIBLE);
			holder.icon1.setVisibility(View.GONE);
			holder.icon2.setVisibility(View.GONE);
			holder.icon.setVisibility(View.GONE);
			holder.postion.setVisibility(View.GONE);
		} else
		{
			holder.postion.setVisibility(View.VISIBLE);
			holder.postion.setText("" + (position + 1));
			holder.icon3.setVisibility(View.GONE);
			holder.icon1.setVisibility(View.GONE);
			holder.icon2.setVisibility(View.GONE);
			holder.icon.setVisibility(View.GONE);
		}

		return convertView;
	}

	class ViewHolder
	{
		private ImageView icon;
		private ImageView icon1;
		private ImageView icon2;
		private ImageView icon3;
		private TextView name;
		private TextView num;
		private TextView postion;
	}
}
